ABAP Select data from SAP table SAPWLHITL into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP SAPWLHITL table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to SAPWLHITL. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the SAPWLHITL table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_SAPWLHITL TYPE STANDARD TABLE OF SAPWLHITL, WA_SAPWLHITL TYPE SAPWLHITL, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <SAPWLHITL> TYPE SAPWLHITL. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_SAPWLHITL. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM SAPWLHITL INTO TABLE IT_SAPWLHITL. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM SAPWLHITL * INTO TABLE @DATA(IT_SAPWLHITL2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_SAPWLHITL INDEX 1 INTO DATA(WA_SAPWLHITL2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_SAPWLHITL ASSIGNING <SAPWLHITL>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<SAPWLHITL>-DATE = 1.
<SAPWLHITL>-RESPTI = 1.
<SAPWLHITL>-DBCALLS = 1.
<SAPWLHITL>-ENDTI = 1.
<SAPWLHITL>-CPUTI = 1.
ENDLOOP. LOOP AT IT_SAPWLHITL INTO WA_SAPWLHITL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_SAPWLHITL-QUEUETI, sy-vline,
WA_SAPWLHITL-V1SATI, sy-vline,
WA_SAPWLHITL-WPID, sy-vline,
WA_SAPWLHITL-TASKTYPE, sy-vline,
WA_SAPWLHITL-TABLOAD, sy-vline,
WA_SAPWLHITL-TCODE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_SAPWLHITL you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_SAPWLHITL TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_SAPWLHITL INTO WA_SAPWLHITL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_SAPWLHITL_STR,
DATE TYPE STRING,
RESPTI TYPE STRING,
DBCALLS TYPE STRING,
ENDTI TYPE STRING,
CPUTI TYPE STRING,
QUEUETI TYPE STRING,
V1SATI TYPE STRING,
WPID TYPE STRING,
TASKTYPE TYPE STRING,
TABLOAD TYPE STRING,
TCODE TYPE STRING,
TERMINALID TYPE STRING,
DYNPRONR TYPE STRING,
REPORT TYPE STRING,
ACCOUNT TYPE STRING,
MANDT TYPE STRING,
ROLLKEY TYPE STRING,
INPUTLEN TYPE STRING,
OUTPUTLEN TYPE STRING,
MAXROLL TYPE STRING,
MAXPAGE TYPE STRING,
ROLLINCNT TYPE STRING,
ROLLINTI TYPE STRING,
ROLLOUTCNT TYPE STRING,
ROLLOUTTI TYPE STRING,
LOCKCNT TYPE STRING,
LOCKTI TYPE STRING,
TABNAME1 TYPE STRING,
TAB1DIRCNT TYPE STRING,
TAB1SEQCNT TYPE STRING,
TAB1UPDCNT TYPE STRING,
TABNAME2 TYPE STRING,
TAB2DIRCNT TYPE STRING,
TAB2SEQCNT TYPE STRING,
TAB2UPDCNT TYPE STRING,
TABNAME3 TYPE STRING,
TAB3DIRCNT TYPE STRING,
TAB3SEQCNT TYPE STRING,
TAB3UPDCNT TYPE STRING,
TABNAME4 TYPE STRING,
TAB4DIRCNT TYPE STRING,
TAB4SEQCNT TYPE STRING,
TAB4UPDCNT TYPE STRING,
TABNAME5 TYPE STRING,
TAB5DIRCNT TYPE STRING,
TAB5SEQCNT TYPE STRING,
TAB5UPDCNT TYPE STRING,
READDIRCNT TYPE STRING,
READDIRTI TYPE STRING,
READDIRREC TYPE STRING,
READDIRBUF TYPE STRING,
READSEQCNT TYPE STRING,
READSEQTI TYPE STRING,
READSEQREC TYPE STRING,
READSEQBUF TYPE STRING,
PHYREADCNT TYPE STRING,
INSCNT TYPE STRING,
INSTI TYPE STRING,
INSREC TYPE STRING,
PHYINSCNT TYPE STRING,
UPDCNT TYPE STRING,
UPDTI TYPE STRING,
UPDREC TYPE STRING,
PHYUPDCNT TYPE STRING,
DELCNT TYPE STRING,
DELTI TYPE STRING,
DELREC TYPE STRING,
PHYDELCNT TYPE STRING,
COMMITTI TYPE STRING,
GENERATETI TYPE STRING,
REPLOADTI TYPE STRING,
CUALOADTI TYPE STRING,
DYNPLOADTI TYPE STRING,
DSQLCNT TYPE STRING,
QUECNT TYPE STRING,
QUETI TYPE STRING,
DDICTI TYPE STRING,
CPICCNT TYPE STRING,
CPICTI TYPE STRING,
TABLEPOINT TYPE STRING,
BTCJOBNAME TYPE STRING,
BTCSTEPNR TYPE STRING,
ROLLED_OUT TYPE STRING,
SLI_CNT TYPE STRING,
USEDBYTES TYPE STRING,
PRIVSUM TYPE STRING,
MAXBYTES TYPE STRING,
MAXBYTESDI TYPE STRING,
PRIVMODE TYPE STRING,
WPRESTART TYPE STRING,
GUITIME TYPE STRING,
GUICNT TYPE STRING,
RFCRECEIVE TYPE STRING,
RFCSEND TYPE STRING,
RFCEXETIME TYPE STRING,
RFCCALLTIM TYPE STRING,
RFCCALLS TYPE STRING,
RFCDATFROM TYPE STRING,
DBP_COUNT TYPE STRING,
DBP_TIME TYPE STRING,
FCODE TYPE STRING,END OF T_EKKO_STR. DATA: WA_SAPWLHITL_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_SAPWLHITL_STR-DATE sy-vline
WA_SAPWLHITL_STR-RESPTI sy-vline
WA_SAPWLHITL_STR-DBCALLS sy-vline
WA_SAPWLHITL_STR-ENDTI sy-vline
WA_SAPWLHITL_STR-CPUTI sy-vline
WA_SAPWLHITL_STR-QUEUETI sy-vline
WA_SAPWLHITL_STR-V1SATI sy-vline
WA_SAPWLHITL_STR-WPID sy-vline
WA_SAPWLHITL_STR-TASKTYPE sy-vline
WA_SAPWLHITL_STR-TABLOAD sy-vline
WA_SAPWLHITL_STR-TCODE sy-vline
WA_SAPWLHITL_STR-TERMINALID sy-vline
WA_SAPWLHITL_STR-DYNPRONR sy-vline
WA_SAPWLHITL_STR-REPORT sy-vline
WA_SAPWLHITL_STR-ACCOUNT sy-vline
WA_SAPWLHITL_STR-MANDT sy-vline
WA_SAPWLHITL_STR-ROLLKEY sy-vline
WA_SAPWLHITL_STR-INPUTLEN sy-vline
WA_SAPWLHITL_STR-OUTPUTLEN sy-vline
WA_SAPWLHITL_STR-MAXROLL sy-vline
WA_SAPWLHITL_STR-MAXPAGE sy-vline
WA_SAPWLHITL_STR-ROLLINCNT sy-vline
WA_SAPWLHITL_STR-ROLLINTI sy-vline
WA_SAPWLHITL_STR-ROLLOUTCNT sy-vline
WA_SAPWLHITL_STR-ROLLOUTTI sy-vline
WA_SAPWLHITL_STR-LOCKCNT sy-vline
WA_SAPWLHITL_STR-LOCKTI sy-vline
WA_SAPWLHITL_STR-TABNAME1 sy-vline
WA_SAPWLHITL_STR-TAB1DIRCNT sy-vline
WA_SAPWLHITL_STR-TAB1SEQCNT sy-vline
WA_SAPWLHITL_STR-TAB1UPDCNT sy-vline
WA_SAPWLHITL_STR-TABNAME2 sy-vline
WA_SAPWLHITL_STR-TAB2DIRCNT sy-vline
WA_SAPWLHITL_STR-TAB2SEQCNT sy-vline
WA_SAPWLHITL_STR-TAB2UPDCNT sy-vline
WA_SAPWLHITL_STR-TABNAME3 sy-vline
WA_SAPWLHITL_STR-TAB3DIRCNT sy-vline
WA_SAPWLHITL_STR-TAB3SEQCNT sy-vline
WA_SAPWLHITL_STR-TAB3UPDCNT sy-vline
WA_SAPWLHITL_STR-TABNAME4 sy-vline
WA_SAPWLHITL_STR-TAB4DIRCNT sy-vline
WA_SAPWLHITL_STR-TAB4SEQCNT sy-vline
WA_SAPWLHITL_STR-TAB4UPDCNT sy-vline
WA_SAPWLHITL_STR-TABNAME5 sy-vline
WA_SAPWLHITL_STR-TAB5DIRCNT sy-vline
WA_SAPWLHITL_STR-TAB5SEQCNT sy-vline
WA_SAPWLHITL_STR-TAB5UPDCNT sy-vline
WA_SAPWLHITL_STR-READDIRCNT sy-vline
WA_SAPWLHITL_STR-READDIRTI sy-vline
WA_SAPWLHITL_STR-READDIRREC sy-vline
WA_SAPWLHITL_STR-READDIRBUF sy-vline
WA_SAPWLHITL_STR-READSEQCNT sy-vline
WA_SAPWLHITL_STR-READSEQTI sy-vline
WA_SAPWLHITL_STR-READSEQREC sy-vline
WA_SAPWLHITL_STR-READSEQBUF sy-vline
WA_SAPWLHITL_STR-PHYREADCNT sy-vline
WA_SAPWLHITL_STR-INSCNT sy-vline
WA_SAPWLHITL_STR-INSTI sy-vline
WA_SAPWLHITL_STR-INSREC sy-vline
WA_SAPWLHITL_STR-PHYINSCNT sy-vline
WA_SAPWLHITL_STR-UPDCNT sy-vline
WA_SAPWLHITL_STR-UPDTI sy-vline
WA_SAPWLHITL_STR-UPDREC sy-vline
WA_SAPWLHITL_STR-PHYUPDCNT sy-vline
WA_SAPWLHITL_STR-DELCNT sy-vline
WA_SAPWLHITL_STR-DELTI sy-vline
WA_SAPWLHITL_STR-DELREC sy-vline
WA_SAPWLHITL_STR-PHYDELCNT sy-vline
WA_SAPWLHITL_STR-COMMITTI sy-vline
WA_SAPWLHITL_STR-GENERATETI sy-vline
WA_SAPWLHITL_STR-REPLOADTI sy-vline
WA_SAPWLHITL_STR-CUALOADTI sy-vline
WA_SAPWLHITL_STR-DYNPLOADTI sy-vline
WA_SAPWLHITL_STR-DSQLCNT sy-vline
WA_SAPWLHITL_STR-QUECNT sy-vline
WA_SAPWLHITL_STR-QUETI sy-vline
WA_SAPWLHITL_STR-DDICTI sy-vline
WA_SAPWLHITL_STR-CPICCNT sy-vline
WA_SAPWLHITL_STR-CPICTI sy-vline
WA_SAPWLHITL_STR-TABLEPOINT sy-vline
WA_SAPWLHITL_STR-BTCJOBNAME sy-vline
WA_SAPWLHITL_STR-BTCSTEPNR sy-vline
WA_SAPWLHITL_STR-ROLLED_OUT sy-vline
WA_SAPWLHITL_STR-SLI_CNT sy-vline
WA_SAPWLHITL_STR-USEDBYTES sy-vline
WA_SAPWLHITL_STR-PRIVSUM sy-vline
WA_SAPWLHITL_STR-MAXBYTES sy-vline
WA_SAPWLHITL_STR-MAXBYTESDI sy-vline
WA_SAPWLHITL_STR-PRIVMODE sy-vline
WA_SAPWLHITL_STR-WPRESTART sy-vline
WA_SAPWLHITL_STR-GUITIME sy-vline
WA_SAPWLHITL_STR-GUICNT sy-vline
WA_SAPWLHITL_STR-RFCRECEIVE sy-vline
WA_SAPWLHITL_STR-RFCSEND sy-vline
WA_SAPWLHITL_STR-RFCEXETIME sy-vline
WA_SAPWLHITL_STR-RFCCALLTIM sy-vline
WA_SAPWLHITL_STR-RFCCALLS sy-vline
WA_SAPWLHITL_STR-RFCDATFROM sy-vline
WA_SAPWLHITL_STR-DBP_COUNT sy-vline
WA_SAPWLHITL_STR-DBP_TIME sy-vline
WA_SAPWLHITL_STR-FCODE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.