ABAP Select data from SAP table FKKBIBILLACC_H_DISP 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 FKKBIBILLACC_H_DISP 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 FKKBIBILLACC_H_DISP. 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 FKKBIBILLACC_H_DISP 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_FKKBIBILLACC_H_DISP TYPE STANDARD TABLE OF FKKBIBILLACC_H_DISP,
      WA_FKKBIBILLACC_H_DISP TYPE FKKBIBILLACC_H_DISP,
      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: <FKKBIBILLACC_H_DISP> TYPE FKKBIBILLACC_H_DISP.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_FKKBIBILLACC_H_DISP.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM FKKBIBILLACC_H_DISP
  INTO TABLE IT_FKKBIBILLACC_H_DISP.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FKKBIBILLACC_H_DISP
*  INTO TABLE @DATA(IT_FKKBIBILLACC_H_DISP2).
*--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_FKKBIBILLACC_H_DISP INDEX 1 INTO DATA(WA_FKKBIBILLACC_H_DISP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FKKBIBILLACC_H_DISP ASSIGNING <FKKBIBILLACC_H_DISP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FKKBIBILLACC_H_DISP>-MANDT = 1.
<FKKBIBILLACC_H_DISP>-BILLACCOUNT = 1.
<FKKBIBILLACC_H_DISP>-BILLACCREF = 1.
<FKKBIBILLACC_H_DISP>-BILLACCREFCAT = 1.
<FKKBIBILLACC_H_DISP>-APPLK = 1.
ENDLOOP.

LOOP AT IT_FKKBIBILLACC_H_DISP INTO WA_FKKBIBILLACC_H_DISP.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FKKBIBILLACC_H_DISP-VKONT, sy-vline,
WA_FKKBIBILLACC_H_DISP-GPART, sy-vline,
WA_FKKBIBILLACC_H_DISP-VTREF, sy-vline,
WA_FKKBIBILLACC_H_DISP-SUBAP, sy-vline,
WA_FKKBIBILLACC_H_DISP-BILLACCTYPE, sy-vline,
WA_FKKBIBILLACC_H_DISP-TS_FROM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FKKBIBILLACC_H_DISP 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_FKKBIBILLACC_H_DISP 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_FKKBIBILLACC_H_DISP INTO WA_FKKBIBILLACC_H_DISP. *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.

*Conversion exit ALPHA, internal->external for field VKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKBIBILLACC_H_DISP-VKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKBIBILLACC_H_DISP-VKONT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field GPART CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKBIBILLACC_H_DISP-GPART IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKBIBILLACC_H_DISP-GPART.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VTREF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKBIBILLACC_H_DISP-VTREF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKBIBILLACC_H_DISP-VTREF.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_FKKBIBILLACC_H_DISP_STR,
MANDT TYPE STRING,
BILLACCOUNT TYPE STRING,
BILLACCREF TYPE STRING,
BILLACCREFCAT TYPE STRING,
APPLK TYPE STRING,
VKONT TYPE STRING,
GPART TYPE STRING,
VTREF TYPE STRING,
SUBAP TYPE STRING,
BILLACCTYPE TYPE STRING,
TS_FROM TYPE STRING,
TS_TO TYPE STRING,
BILLACCTIMEZONE TYPE STRING,
LOADTO TYPE STRING,
BILLEDTO TYPE STRING,
BILLEDTOTEMP TYPE STRING,
BILLCYCLE TYPE STRING,
BILLGROUP TYPE STRING,
BC_VALIDTO TYPE STRING,
HOTBILLING TYPE STRING,
BILLLOCKREASON TYPE STRING,
BILLLOCKRELEASE TYPE STRING,
KOFIZ TYPE STRING,
BEGRU TYPE STRING,
TARGPROCESS1 TYPE STRING,
CRNAME TYPE STRING,
CRTIMESTAMP TYPE STRING,
CHNAME TYPE STRING,
CHTIMESTAMP TYPE STRING,
DATEFROM TYPE STRING,
TIMEFROM TYPE STRING,
DATETO TYPE STRING,
TIMETO TYPE STRING,
DATELASTBILLEDTO TYPE STRING,
TIMELASTBILLEDTO TYPE STRING,
LASTBILLDOCNO TYPE STRING,
DATEBILLEDTOTEMP TYPE STRING,
TIMEBILLEDTOTEMP TYPE STRING,
DATENEXTBILLTO TYPE STRING,
TIMENEXTBILLTO TYPE STRING,
NEXTBILLPROCEDURE TYPE STRING,
DATELOADTO TYPE STRING,
TIMELOADTO TYPE STRING,
DATEBCVALIDTO TYPE STRING,
TIMEBCVALIDTO TYPE STRING,
CHDATE TYPE STRING,
CHTIME TYPE STRING,
CRDATE TYPE STRING,
CRTIME TYPE STRING,END OF T_EKKO_STR. DATA: WA_FKKBIBILLACC_H_DISP_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_FKKBIBILLACC_H_DISP_STR-MANDT sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLACCOUNT sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLACCREF sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLACCREFCAT sy-vline
WA_FKKBIBILLACC_H_DISP_STR-APPLK sy-vline
WA_FKKBIBILLACC_H_DISP_STR-VKONT sy-vline
WA_FKKBIBILLACC_H_DISP_STR-GPART sy-vline
WA_FKKBIBILLACC_H_DISP_STR-VTREF sy-vline
WA_FKKBIBILLACC_H_DISP_STR-SUBAP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLACCTYPE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TS_FROM sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TS_TO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLACCTIMEZONE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-LOADTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLEDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLEDTOTEMP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLCYCLE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLGROUP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BC_VALIDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-HOTBILLING sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLLOCKREASON sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BILLLOCKRELEASE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-KOFIZ sy-vline
WA_FKKBIBILLACC_H_DISP_STR-BEGRU sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TARGPROCESS1 sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CRNAME sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CRTIMESTAMP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CHNAME sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CHTIMESTAMP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATEFROM sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMEFROM sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATETO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMETO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATELASTBILLEDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMELASTBILLEDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-LASTBILLDOCNO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATEBILLEDTOTEMP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMEBILLEDTOTEMP sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATENEXTBILLTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMENEXTBILLTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-NEXTBILLPROCEDURE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATELOADTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMELOADTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-DATEBCVALIDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-TIMEBCVALIDTO sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CHDATE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CHTIME sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CRDATE sy-vline
WA_FKKBIBILLACC_H_DISP_STR-CRTIME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.