Let us ABAP 7.40

C:UsersParthaDesktopHANAimage002.jpg


Today, obviously your company/client running their SAP on latest version ABAP 7.40 (although super latest is 7.50)
Please check it before proceeding further.
You have checked it by now and found its ABAP 7.40
Great!! Now you can dig into the rest of the post. 
You can simply copy paste the code below and enjoy the “NEW WAY” of coding! 
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
* On the fly Data declaration for VARIABLE.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*

*—————————————————————————————————————
****************************************OLD WAY****************************************
*DATA: v_var1 type string.
*
*v_var1 = ‘Hello ABAP 7.40’.
*
*WRITE:/ v_var1.
*—————————————————————————————————————

*—————————————————————————————————————
*****************************************NEW WAY*********************************
DATA(v_var1) = ‘Hello ABAP 7.40’.

WRITE:/ v_var1.
*—————————————————————————————————————
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* On the fly Data declaration for WORK AREA / FIELD-SYMBOL
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TYPESBEGIN OF ty_ekko,
                  ebeln  TYPE ebeln,
                  bukrs  TYPE bukrs,
                  bsart   TYPE esart,
                  aedat  TYPE erdat,
                  ernam TYPE ernam,
               END OF ty_ekko.

DATAlt_ekko TYPE STANDARD TABLE OF ty_ekko.

SELECT ebeln
                 bukrs
                 bsart
                 aedat
                 ernam
       from ekko
       into TABLE lt_ekko
       where ernam syuname.


*—————————————————————————————————————
****************************************OLD WAY***********************************
*DATA: ls_ekko TYPE ekko.
*FIELD-SYMBOLS: <lfs_ekko>.
*DATA: lv_count TYPE i.

*  LOOP AT lt_ekko INTO ls_ekko.
*     WRITE:/ ls_ekko-ebeln,
*             ls_ekko-aedat.
*  ENDLOOP.

*  LOOP AT lt_ekko ASSIGNING <lfs_ekko>.
*     WRITE:/ <lfs_ekko>-ebeln,
*             <lfs_ekko>-aedat.
*  ENDLOOP.

*DESCRIBE TABLE lt_ekko LINES lv_count.
*—————————————————————————————————————
*****************************************NEW WAY*********************************
  LOOP AT lt_ekko INTO DATA(ls_ekko).
     WRITE:/ ls_ekkoebeln,
                      ls_ekkoaedat.
  ENDLOOP.

  LOOP AT lt_ekko ASSIGNING FIELDSYMBOL(<lfs_ekko>).
     WRITE:/ <lfs_ekko>ebeln,
                      <lfs_ekko>aedat.
  ENDLOOP.

  DESCRIBE TABLE lt_ekko LINES DATA(lv_count).
*—————————————————————————————————————

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* On the fly READ operation.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*—————————————————————————————————————
****************************************OLD WAY***********************************
*  DATA: ls_ekko_2 TYPE ty_ekko.
*  READ TABLE lt_ekko INTO ls_ekko_2 INDEX 2.
*  IF sy-subrc IS INITIAL.
*  WRITE:/ ‘2nd PO found’.
*  ENDIF.

*  DATA: ls_ekko_cond TYPE ty_ekko.
*  READ TABLE lt_ekko INTO ls_ekko_cond WITH KEY ebeln = ‘4500017750’.
*  IF sy-subrc IS INITIAL.
*  WRITE:/ ‘PO found’.
*  ENDIF.

*  DATA: ls_ekko_exist TYPE ty_ekko.
*  READ TABLE lt_ekko WITH KEY ebeln = ‘4500017750’
*                              TRANSPORTING NO FIELDS.
*  IF sy-subrc IS INITIAL.
*    WRITE:/ ‘PO Exist’.
*  ENDIF.

*—————————————————————————————————————
*****************************************NEW WAY*********************************
  DATA(ls_ekko_2) = lt_ekko[ ].
  WRITE:‘2nd PO found’.

  DATA(ls_ekko_cond) = lt_ekko[ ebeln ‘4500017750’ ].
  WRITE:‘PO found’.

  IF line_existslt_ekko[ ebeln ‘4500017750’ ).
    WRITE:‘PO Exist’.
  ENDIF.
Here is some more examples which will help you to explore more into ABAP 7.40


C:UsersParthaDesktopHANAimage004.jpg


C:UsersParthaDesktopHANAimage006.jpg 

Leave a Reply

Your email address will not be published. Required fields are marked *