API to create Code Combination and get CCID

----API To Create Bulk GL Code Combinations
DECLARE    
l_ledger_name       VARCHAR2(300)DEFAULT 'JGTECH_INDIA_PRIMARY_LEDGER';
l_structure_number  NUMBER;
l_sucess            BOOLEAN;
  
  CURSOR CUR 
  IS
  
      SELECT a.rowid rid,
            a.emp_code,
            a.code_combination
        FROM xx_emp_code_comb a
        WHERE  code_comb_id is null;
BEGIN

  SELECT chart_of_accounts_id
    INTO l_structure_number
    FROM gl_ledgers
   WHERE name = l_ledger_name;
   
 FOR i IN cur LOOP
  lb_sucess := fnd_flex_keyval.validate_segs
            (
             operation           => 'CREATE_COMBINATION',
             appl_short_name     => 'SQLGL',
             key_flex_code       => 'GL#',
             structure_number    => l_structure_number,
             concat_segments     => i.code_combination, 
             validation_date     => SYSDATE
            );
            
  IF l_sucess
  THEN
    DBMS_OUTPUT.PUT_LINE('Successful. Code Combination ID: '||fnd_flex_keyval.combination_id());
    UPDATE xx_emp_code_comb aa
    SET code_comb_id=fnd_flex_keyval.combination_id()
    WHERE aa.emp_code=i.emp_code;
    
  ELSE
    DBMS_OUTPUT.PUT_LINE('Error creating a Code combination id for ' ||'/i.code_combination/'||' Error:'|| fnd_flex_keyval.error_message());
  END IF;
 END LOOP;
       COMMIT;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Unable to create a code combination for ' ||'/'||' Error:'|| SQLERRM);

END;