ABAP Select data from SAP table TCORS_CODLC_ALL 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 TCORS_CODLC_ALL 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 TCORS_CODLC_ALL. 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 TCORS_CODLC_ALL 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_TCORS_CODLC_ALL TYPE STANDARD TABLE OF TCORS_CODLC_ALL,
      WA_TCORS_CODLC_ALL TYPE TCORS_CODLC_ALL,
      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: <TCORS_CODLC_ALL> TYPE TCORS_CODLC_ALL.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TCORS_CODLC_ALL
*  INTO TABLE @DATA(IT_TCORS_CODLC_ALL2).
*--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_TCORS_CODLC_ALL INDEX 1 INTO DATA(WA_TCORS_CODLC_ALL2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TCORS_CODLC_ALL ASSIGNING <TCORS_CODLC_ALL>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TCORS_CODLC_ALL>-MANDT = 1.
<TCORS_CODLC_ALL>-CODLC_UUID = 1.
<TCORS_CODLC_ALL>-CODMD_UUID = 1.
<TCORS_CODLC_ALL>-LC_NUMBER = 1.
<TCORS_CODLC_ALL>-BENFICIARY = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TCORS_CODLC_ALL-ADVISING_BANK, sy-vline,
WA_TCORS_CODLC_ALL-ISSUING_BANK, sy-vline,
WA_TCORS_CODLC_ALL-APPLICANT, sy-vline,
WA_TCORS_CODLC_ALL-CREDIT_AMT, sy-vline,
WA_TCORS_CODLC_ALL-CRE_AMT_CUR, sy-vline,
WA_TCORS_CODLC_ALL-TOLERANCE_POS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TCORS_CODLC_ALL 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_TCORS_CODLC_ALL 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_TCORS_CODLC_ALL INTO WA_TCORS_CODLC_ALL. *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 BENFICIARY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TCORS_CODLC_ALL-BENFICIARY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TCORS_CODLC_ALL-BENFICIARY.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ALPHA, internal->external for field APPLICANT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TCORS_CODLC_ALL-APPLICANT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TCORS_CODLC_ALL-APPLICANT.
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_TCORS_CODLC_ALL_STR,
MANDT TYPE STRING,
CODLC_UUID TYPE STRING,
CODMD_UUID TYPE STRING,
LC_NUMBER TYPE STRING,
BENFICIARY TYPE STRING,
ADVISING_BANK TYPE STRING,
ISSUING_BANK TYPE STRING,
APPLICANT TYPE STRING,
CREDIT_AMT TYPE STRING,
CRE_AMT_CUR TYPE STRING,
TOLERANCE_POS TYPE STRING,
TOLERANCE_NEG TYPE STRING,
MAX_CREDIT_AMT TYPE STRING,
PARTIAL_SHIP TYPE STRING,
PRES_PLACE TYPE STRING,
DEFERRED_DAYS TYPE STRING,
SHIP_METHOD TYPE STRING,
CHARGE_PLACE TYPE STRING,
LOAD_PLACE TYPE STRING,
DEST_PLACE TYPE STRING,
FINAL_DEST TYPE STRING,
MOL_TYPE TYPE STRING,
INCO1 TYPE STRING,
INCO2 TYPE STRING,
SFHAZBA TYPE STRING,
TRANSHIP_ALLOW TYPE STRING,
CHARGE_PAID_BY TYPE STRING,
PAYMENT_AT TYPE STRING,
CONFIRM_INSTR TYPE STRING,
MOL_TERM TYPE STRING,
SHIP_PER_FROM TYPE STRING,
SHIP_PER_TO TYPE STRING,
PRESENT_DAY TYPE STRING,
PRESENT_PER_CON_ID TYPE STRING,
PAYMENT_TERM TYPE STRING,
USANCE TYPE STRING,
PAYMENT_PER_CON_ID TYPE STRING,
MAN_BENFICIARY TYPE STRING,
MAN_ADVISING_BANK TYPE STRING,
MAN_APPLICANT TYPE STRING,
MAN_ISSUING_BANK TYPE STRING,
MAN_COMP_NAME TYPE STRING,
MAN_COMP_ADDR TYPE STRING,
MAN_COMP_FAX TYPE STRING,
MAN_COMP_CNT_PER TYPE STRING,
MAN_COMP_CNT_NUM TYPE STRING,
MAN_BANK_NAME TYPE STRING,
MAN_BANK_ADDR TYPE STRING,
MAN_BANK_FAX TYPE STRING,
MAN_BANK_CNT_PER TYPE STRING,
MAN_BANK_CNT_NUM TYPE STRING,
MAN_BANK_SWIFT TYPE STRING,
TIME_ZONE TYPE STRING,
BG_NUMBER TYPE STRING,
BG_TYPE TYPE STRING,
BG_FORM TYPE STRING,
GUARANTEED_PERCENT TYPE STRING,
CONTRACT_NUMBER TYPE STRING,
CONTRACT_DATE TYPE STRING,
CONTRACT_AMOUNT TYPE STRING,
UNDERLYING_TRANS_ID TYPE STRING,
AUTO_EXT_NOTICE_DAYS TYPE STRING,
AUTO_EXT_PERIOD TYPE STRING,
AUTO_EXT_PERIOD_TYPE TYPE STRING,
AUTO_EXT_FIN_EXPIRY_DATE TYPE STRING,
DRAW_MODE TYPE STRING,
PRESENTATION TYPE STRING,END OF T_EKKO_STR. DATA: WA_TCORS_CODLC_ALL_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_TCORS_CODLC_ALL_STR-MANDT sy-vline
WA_TCORS_CODLC_ALL_STR-CODLC_UUID sy-vline
WA_TCORS_CODLC_ALL_STR-CODMD_UUID sy-vline
WA_TCORS_CODLC_ALL_STR-LC_NUMBER sy-vline
WA_TCORS_CODLC_ALL_STR-BENFICIARY sy-vline
WA_TCORS_CODLC_ALL_STR-ADVISING_BANK sy-vline
WA_TCORS_CODLC_ALL_STR-ISSUING_BANK sy-vline
WA_TCORS_CODLC_ALL_STR-APPLICANT sy-vline
WA_TCORS_CODLC_ALL_STR-CREDIT_AMT sy-vline
WA_TCORS_CODLC_ALL_STR-CRE_AMT_CUR sy-vline
WA_TCORS_CODLC_ALL_STR-TOLERANCE_POS sy-vline
WA_TCORS_CODLC_ALL_STR-TOLERANCE_NEG sy-vline
WA_TCORS_CODLC_ALL_STR-MAX_CREDIT_AMT sy-vline
WA_TCORS_CODLC_ALL_STR-PARTIAL_SHIP sy-vline
WA_TCORS_CODLC_ALL_STR-PRES_PLACE sy-vline
WA_TCORS_CODLC_ALL_STR-DEFERRED_DAYS sy-vline
WA_TCORS_CODLC_ALL_STR-SHIP_METHOD sy-vline
WA_TCORS_CODLC_ALL_STR-CHARGE_PLACE sy-vline
WA_TCORS_CODLC_ALL_STR-LOAD_PLACE sy-vline
WA_TCORS_CODLC_ALL_STR-DEST_PLACE sy-vline
WA_TCORS_CODLC_ALL_STR-FINAL_DEST sy-vline
WA_TCORS_CODLC_ALL_STR-MOL_TYPE sy-vline
WA_TCORS_CODLC_ALL_STR-INCO1 sy-vline
WA_TCORS_CODLC_ALL_STR-INCO2 sy-vline
WA_TCORS_CODLC_ALL_STR-SFHAZBA sy-vline
WA_TCORS_CODLC_ALL_STR-TRANSHIP_ALLOW sy-vline
WA_TCORS_CODLC_ALL_STR-CHARGE_PAID_BY sy-vline
WA_TCORS_CODLC_ALL_STR-PAYMENT_AT sy-vline
WA_TCORS_CODLC_ALL_STR-CONFIRM_INSTR sy-vline
WA_TCORS_CODLC_ALL_STR-MOL_TERM sy-vline
WA_TCORS_CODLC_ALL_STR-SHIP_PER_FROM sy-vline
WA_TCORS_CODLC_ALL_STR-SHIP_PER_TO sy-vline
WA_TCORS_CODLC_ALL_STR-PRESENT_DAY sy-vline
WA_TCORS_CODLC_ALL_STR-PRESENT_PER_CON_ID sy-vline
WA_TCORS_CODLC_ALL_STR-PAYMENT_TERM sy-vline
WA_TCORS_CODLC_ALL_STR-USANCE sy-vline
WA_TCORS_CODLC_ALL_STR-PAYMENT_PER_CON_ID sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BENFICIARY sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_ADVISING_BANK sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_APPLICANT sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_ISSUING_BANK sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_COMP_NAME sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_COMP_ADDR sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_COMP_FAX sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_COMP_CNT_PER sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_COMP_CNT_NUM sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_NAME sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_ADDR sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_FAX sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_CNT_PER sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_CNT_NUM sy-vline
WA_TCORS_CODLC_ALL_STR-MAN_BANK_SWIFT sy-vline
WA_TCORS_CODLC_ALL_STR-TIME_ZONE sy-vline
WA_TCORS_CODLC_ALL_STR-BG_NUMBER sy-vline
WA_TCORS_CODLC_ALL_STR-BG_TYPE sy-vline
WA_TCORS_CODLC_ALL_STR-BG_FORM sy-vline
WA_TCORS_CODLC_ALL_STR-GUARANTEED_PERCENT sy-vline
WA_TCORS_CODLC_ALL_STR-CONTRACT_NUMBER sy-vline
WA_TCORS_CODLC_ALL_STR-CONTRACT_DATE sy-vline
WA_TCORS_CODLC_ALL_STR-CONTRACT_AMOUNT sy-vline
WA_TCORS_CODLC_ALL_STR-UNDERLYING_TRANS_ID sy-vline
WA_TCORS_CODLC_ALL_STR-AUTO_EXT_NOTICE_DAYS sy-vline
WA_TCORS_CODLC_ALL_STR-AUTO_EXT_PERIOD sy-vline
WA_TCORS_CODLC_ALL_STR-AUTO_EXT_PERIOD_TYPE sy-vline
WA_TCORS_CODLC_ALL_STR-AUTO_EXT_FIN_EXPIRY_DATE sy-vline
WA_TCORS_CODLC_ALL_STR-DRAW_MODE sy-vline
WA_TCORS_CODLC_ALL_STR-PRESENTATION sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.