TIP of the Day #ABAP

TIP of the Day #ABAP

#sap #sapabap ?#learntogether?#abaponhana?#tipoftheday

Read internal table in Modern ABAP

New ABAP features from Netweaver 7.40 allows the developers to read an internal table in much easier way. There are few points to be considered while following this new syntax.

Before Netweaver 7.40, 'Read table' statement is used to read data from an internal table. This statement also sets sy-subrc and sy-tabix depending on Read statement execution, offers more features like Binary search.

$OLD ABAP

READ TABLE lt_ekko INTO wa_ekko WITH KEY EBELN = '100000001'
                                         BINARY SEARCH.
IF SY_SUBRC = 0.
WRITE : wa_ekko-ebeln.
ENDIF.

$NEW ABAP

wa_ekko = lt_ekko [ EBELN = '100000001']        

New syntax offers better readability and ease of use, but statement will result in unexpected system error with exception 'CX_SY_ITAB_LINE_NOT_FOUND' if no data matching the key parameters. Always use new syntax in Try..Catch block to ensure exceptions are handled.

New features like LINE_EXISTS, LINE_INDEX can also be used along with new read syntax.

$NEW ABAP - OPTION 1

TRY
DATA(wa_ekko) = lt_ekko [ EBELN = '100000001' ]
WRITE : wa_ekko-ebeln.
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
WRITE : 'NO RECORD FOUND'.
ENDTRY

OPTION 2

IF LINE_EXISTS( lt_ekko [ EBELN = '100000001' ] )
DATA(wa_ekko) = lt_ekko [ EBELN = '100000001' ]
WRITE : wa_ekko-ebeln.
ELSE.
WRITE : 'NO RECORD FOUND'.
ENDIF.        

Either option 1 or option 2 can be followed with new syntax to avoid unexpected system error.

ABAP TIP of the Day: I will be sharing my learnings in ABAP and Modern ABAP through the series ABAP TIP of the Day. Hope this helps our developer community. Let's share and learn together!!

Ragavendran R

Integration Managing Consultant - BTP Integration Suite|| PI/PO/EDI || SAP Certified Cloud Integration Associate || Workato Automation Pro 2 Certified || Jitterbit Certified Consultant || Celigo Certified Consultant

1 年

Good job bro

Arun Kumar Solaiyan

SAP ABAP | S4 HANA | RAP | BTP | Integration suite CPI and PI

1 年

ABAP Tip of the day #002

回复

要查看或添加评论,请登录

Arun Kumar Solaiyan的更多文章

  • SAP Extensibility

    SAP Extensibility

    #SAP #ABAP #S/4HANA #ABAPonCloud #ABAPonBTP #Extensibility SAP S4 HANA Cloud Public Edition allows customers and…

    1 条评论
  • SAP Extensibility

    SAP Extensibility

    #SAP #ABAP #S/4HANA #ABAPonCloud #ABAPonBTP #Extensibility SAP Extensibility enables customers to adopt business…

    1 条评论
  • CONV # Operator in New ABAP

    CONV # Operator in New ABAP

    CONV # operator is used to convert a value to datatype specified on the go. Whenever we pass values to class methods or…

  • Quick Fix and Quick Assist in New ABAP

    Quick Fix and Quick Assist in New ABAP

    As the name suggests, Quick Assist and Quick Fix options from ADT improves the ABAP development experience and faster…

    1 条评论
  • LOOP AT with GROUP BY-NEW ABAP

    LOOP AT with GROUP BY-NEW ABAP

    LOOP AT with GROUP BY - groups the rows of the internal table and executes a loop across the groups. There are two…

  • Mesh - Forward and Inverse association

    Mesh - Forward and Inverse association

    Mesh table type option provides the developer to create relationship between internal tables through association. Data…

    1 条评论
  • MESH Table type in New ABAP

    MESH Table type in New ABAP

    #sap #sapabap #learntogether #abaponhana #tipoftheday MESH Table type option allows the developer to create…

    1 条评论
  • Search for IDOCs by content

    Search for IDOCs by content

    #sap #sapabap #learntogether #abaponhana #tipoftheday Transaction WE02 / WE05 provides an IDOC browser where IDOCs are…

    1 条评论
  • Corresponding # in New ABAP

    Corresponding # in New ABAP

    #sap #sapabap #learntogether #abaponhana #tipoftheday CORRESPONDING function in ABAP helps to perform…

    4 条评论
  • FILTER in New ABAP

    FILTER in New ABAP

    #SAP #SAPABAP #learntogether #NewABAP #tipoftheday FILTER option in New ABAP. FILTER provides a way to query an…

社区洞察

其他会员也浏览了